package com.hangzhou.welbeing.welbeinginstrument.bean;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 10 月 03.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.welbeinginstrument.bean
 * 工程名 welbeing_pregnant
 */
public class EveryDayArticlesListAdapter extends  RecyclerView.Adapter<EveryDayArticlesListAdapter.ViewHolder> implements View.OnClickListener {
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private Context mcontext;
    private List<ReadingEveryDayDateBean.DataBean> mlist = new ArrayList<>();
    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    public EveryDayArticlesListAdapter(List<ReadingEveryDayDateBean.DataBean> mlist1, Context mcontent) {
        mlist.addAll(mlist1);
        mcontext = mcontent;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_every_day_aritcless_list_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_content.setText(mlist.get(position).intro);
        Glide.with(mcontext).load(RBConstants.SERVER_URL+"/Public/Uploads/"+mlist.get(position).art_url).into(holder.iv_caricature);
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(v);
        }
    }

    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_content;

        private ImageView iv_caricature;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_content =  (TextView) itemView.findViewById(R.id.item_every_day_aritcless_list_recyclerview_tv_content);

            iv_caricature =  (ImageView) itemView.findViewById(R.id.item_every_day_aritcless_list_recyclerview_iv_caricature);
        }
    }
}
